package com.sun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sun.dto.DrugDto;
import com.sun.entity.Category;
import com.sun.entity.Drug;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Project: hospitalDrugInformationManagement
 * @Author: 86178
 * @Date: 2023/2/21 16:59
 * @FileName: DurgMapper
 * @Description: "药品数据类"
 */
@Mapper
public interface DrugMapper extends BaseMapper<Drug> {
    @Select("SELECT `name`,count(drug_id) AS categoryNum FROM  category left JOIN `drug` ON drug.category_id = category.category_id\n" +
            "GROUP BY category.`name`")
    public List<DrugDto> selectAll();

    @Select("SELECT count(*) FROM drug")
    public int countDrug();

    @Select("SELECT `name`,count(*) AS categoryNum FROM `drug`,category WHERE drug.category_id = category.category_id\n" +
            "GROUP BY category.`name`")
    public List<Category> countByCategoryId();
}
